package com.easysoft.framework.action;

import com.easysoft.framework.annotation.logs.SystemControllerLog;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.chat.model.SysChatrecord;
import com.easysoft.framework.chat.model.SysChatrecordQuery;
import com.easysoft.framework.chat.model.SysChatrecordView;
import com.easysoft.framework.chat.service.SysChatrecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by try on 2017/8/27.
 */

@RestController
@RequestMapping(value = SystemChatRecordAction.BASE_VIEW)
public class SystemChatRecordAction {

    public static final String BASE_VIEW = "/chatRecord";
    private static final Logger logger = LoggerFactory.getLogger(SystemChatRecordAction.class);


    @Autowired
    @Qualifier("service.SysChatrecordService")
    private SysChatrecordService sysChatrecordService;

    /**
     * 聊天回复列表
     *
     * @param page
     * @param query
     * @return
     */
    @RequestMapping(value = "/listChatrecord", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView listChatrecord(Page page, SysChatrecordQuery query) {
        logger.info("Call SysChatRecordAction.listChatrecord({},{})", page.toString(), query.toString());
        List<SysChatrecordView> listChatrecord = sysChatrecordService.selectSysChatrecordListByPage( query,page);
        ModelAndView mv = new ModelAndView(BASE_VIEW + "/listChatrecord");
        mv.addObject("page", page); // 返回分页
        mv.addObject("query", query);// 查询条件
        mv.addObject("listChatrecord", listChatrecord); // 返回查询结果集
        return mv;
    }

    /**
     * 添加聊天室
     *
     * @param sysChatrecord
     * @param session
     * @return
     */
    @RequestMapping(value = "/addSysChatrecord", method = RequestMethod.POST)
    @SystemControllerLog(description = "添加聊天回复")
    public int addSysChatrecord(SysChatrecord sysChatrecord, HttpSession session) {
        logger.info("Call SysChatRecordAction.addSysChatrecord({})", sysChatrecord.toString());
        return sysChatrecordService.addSysChatrecord(sysChatrecord);

    }

    /**
     * 查询回复聊天记录
     * @param id
     * @return
     */
    @RequestMapping(value = "/viewSysChatrecord", method = RequestMethod.POST)
    public SysChatrecord viewSysChatrecord(String id) {
        logger.info("Call SysChatRecordAction.viewSysChatrecord({})", id);
        return sysChatrecordService.selectSysChatrecordById(id);
    }

    /**
     *  更新聊天回复记录
     * @param sysChatrecord
     * @return
     */
    @RequestMapping(value = "/updateSysChatrecord", method = RequestMethod.POST)
    @SystemControllerLog(description = "更新聊天回复记录")
    public int updateSysChatrecord(SysChatrecord  sysChatrecord) {
        logger.info("Call SysChatRecordAction.updateSysChatrecord({})", sysChatrecord.toString());
        return sysChatrecordService.updateSysChatrecord(sysChatrecord);
    }

    /**
     * 删除聊天回复记录
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteSysChatrecord", method = RequestMethod.POST)
    @SystemControllerLog(description = "删除聊天回复记录")
    public int deleteSysChatrecord(String id) {
        logger.info("Call SysChatRecordAction.deleteSysChatrecord({})", id);
        return sysChatrecordService.deleteSysChatrecord(id);
    }
}
